<template>
  <div>
    {{lista}}
    <el-table
      :data="lista"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
    
      <el-table-column prop="id" label="规格编号"> </el-table-column>
      
      <el-table-column prop="specsname" label="规格名称" width="180">
      </el-table-column>

      <el-table-column   label="规格属性" width="180">
        <template slot-scope='scope'> 
         <el-tag v-for='item in scope.row.attrs' :key='item'>{{item}}</el-tag>
        </template>
      </el-table-column>

     

      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1" type="success">启用</el-tag>
          <el-tag v-else type="info">未启用</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="150px">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="edit(scope.row.id)"
            >编辑</el-button
          >
          <el-button type="danger" size="small" @click="del(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { reqspecsdelete } from "../../../request/api";
import { successAlert } from '../../../utils/alert'
import { mapActions,mapGetters }from 'vuex'
export default {
  data() {
    return {};
  },
  created() {},
  mounted() {
  
     this.reqlist()
   
  },
  computed:{
    ...mapGetters({
      lista:"specs/list"
    })
  },
  methods: {
    ...mapActions({
      reqlist:'specs/reqlist'
    }),
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          reqspecsdelete({ id: id }).then((res) => {
            if (res.data.code == 200) {
                // 如果删除弹出删除成功
              successAlert(res.data.msg)
            // 提醒父组件重新加载列表页面
             this.reqlist()
            }
            
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    edit(id) {
      this.$emit("edit", id);
    },
  },
};
</script>

<style scoped >
</style>
